﻿using System;
using System.Data;
using System.Collections.Generic;

using Catering_Model;
using Catering_Operation;
namespace Catering_Rules
{
	/// <summary>
	/// Dish
	/// </summary>
	public partial class T_Dish
	{
		private readonly D_Dish dal=new D_Dish();
		public T_Dish()
		{}
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(E_Dish model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(E_Dish model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            return dal.Delete(id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            return dal.DeleteList(idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public E_Dish GetModel(int id)
        {

            return dal.GetModel(id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<E_Dish> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<E_Dish> DataTableToList(DataTable dt)
        {
            List<E_Dish> modelList = new List<E_Dish>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                E_Dish model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new E_Dish();
                    if (dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    model.AreaIDS = dt.Rows[n]["AreaIDS"].ToString();
                    model.Name = dt.Rows[n]["Name"].ToString();
                    model.Characteristic = dt.Rows[n]["Characteristic"].ToString();
                    model.Back = dt.Rows[n]["Back"].ToString();
                    model.Picture = dt.Rows[n]["Picture"].ToString();
                    if (dt.Rows[n]["FMID"].ToString() != "")
                    {
                        model.FMID = int.Parse(dt.Rows[n]["FMID"].ToString());
                    }
                    if (dt.Rows[n]["DTID"].ToString() != "")
                    {
                        model.DTID = int.Parse(dt.Rows[n]["DTID"].ToString());
                    }
                    model.Method = dt.Rows[n]["Method"].ToString();
                    if (dt.Rows[n]["IsStuffing"].ToString() != "")
                    {
                        model.IsStuffing = int.Parse(dt.Rows[n]["IsStuffing"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method

        #region 扩展方法

        public int Addd(Catering_Model.E_Dish Model)
        {
            return dal.Addd(Model);
        }

        /// <summary>
        /// 获取总记录数
        /// </summary>
        /// <param name="strWhere">查询条件</param>
        /// <returns>返回记录数</returns>
        public int GetCount(string strWhere)
        {
            return dal.GetCount(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere, string field)
        {
            return dal.GetList(strWhere, field);
        }

        /// <summary>
        /// 更新菜品对应的区域ID 集合
        /// </summary>
        /// <param name="DishID"></param>
        /// <returns></returns>
        public bool UpdateAreaIDByDishID(int DishID)
        {
            return dal.UpdateAreaIDByDishID(DishID);
        }
        #endregion
    }
}

